package com.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/************************************
 * @author : zeck.tang
 * @date : 2014-2-20
 * @description : date util class
 * @history : 1. 2014-2-20 create by zeck.tang
 ************************************/
public class MyDateUtils {

	/** @Description flag for get date millisecond --today */
	public static final int TODAY = 99;

	/** @Description flag for get date millisecond --yesterday */
	public static final int YESTERDAY = 98;

	/**********************************
	 * @author : zeck.tang
	 * @description : get today date
	 * @return date string by format yyyy-MM-dd
	 * @date : 2013-2-20
	 **********************************/
	public static String getToday() {
		String today = "";
		Date dt = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		today = sdf.format(dt);
		return today;
	}

	/**********************************
	 * @author : zeck.tang
	 * @description : get today date
	 * @return date string by format yyyy-MM-dd
	 * @date : 2013-2-20
	 **********************************/
	public static long getDateyMillis(int flag) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = sdf.parse(MyDateUtils.getToday());
		} catch (Exception e) {
			date = null;
		}

		if (date != null) {
			long rtnVal = 0l;
			switch (flag) {
			case TODAY: {
				rtnVal = date.getTime();
			}
				break;
			case YESTERDAY: {
				// today minus 24 hours
				rtnVal = date.getTime() - (24 * 60 * 60 * 1000);
			}
				break;
			}
			return rtnVal;
		} else {
			return 0;
		}

	}
}
